﻿using System;
using System.Collections.Generic;
using Xin478.CSWork.DomainModel;
using Xin478.CSWork.Common;
using Xin478.MySocket;

namespace Xin478.CSWork.Server
{
    public class User : ResponseBase
    {
        public void Login(NetEventArgs e, string username, string password)
        {
            EmployeeInfo employeeInfo = EmployeeModel.Select(Databases.MyWork, username, password);
            this.correspondent.Send(e, "用户登录", employeeInfo);

            if (employeeInfo != null)
                this.correspondent.OnlineUser.Add(e.Client, employeeInfo);
        }

        public void Logout(NetEventArgs e)
        {
            this.correspondent.OnlineUser.Delete(e.Client);
        }

        public void 用户资料(NetEventArgs e, int userId)
        {
            EmployeeInfo ei = EmployeeModel.Select(Databases.MyWork, userId);
            if (ei != null)
            {
                ei.PassWord = null;
                this.correspondent.Send(e, "用户资料", ei);
            }
        }

        public void 用户列表(NetEventArgs e, int groupId)
        {
            IList<EmployeeInfo> employees = EmployeeModel.GroupEmployeeList(Databases.MyWork, groupId);
            if (employees != null)
            {
                foreach (EmployeeInfo employee in employees)
                {
                    employee.PassWord = null;
                    if (this.correspondent.OnlineUser.IsOnline(employee.Id))
                        employee.IsOnline = true;
                }
            }
            this.correspondent.Send(e, "部门用户列表", groupId, employees);
        }

    }
}
